package com.tianyi.sfzy1.controller;

import com.tianyi.sfzy1.domain.Featuredarticle;
import com.tianyi.sfzy1.mapper.FeaturedarticleMapper;
import com.tianyi.sfzy1.service.FeaturedarticleService;
import com.tianyi.sfzy1.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/featuredarticle")
public class FeaturedarticleController {
    @Autowired
    private FeaturedarticleService featuredarticleService;

    //查询所有
    @GetMapping
    public R findAll(){
        return R.ok(featuredarticleService.findAll());
    }

    //根据id查询
   @GetMapping("/findbyid")
//    public R selectByPrimaryKey ( int articleId){
//        return R.ok(featuredarticleService.selectByPrimaryKey(articleId));
//    }
   public R selectByPrimaryKey(int articleId) {

       System.out.println(articleId);
       Featuredarticle featuredarticle=featuredarticleService.selectByPrimaryKey(articleId);
       System.out.println(featuredarticle);
       return R.ok(featuredarticle);
   }
   //分页查询
    @GetMapping("/findbypage")
    public R findByPage(int start, int pageSize){
        return R.ok(featuredarticleService.findByPage(start, pageSize));
    }
    //修改
    @PutMapping
    public R updateByPrimaryKey( Featuredarticle featuredarticle){
        System.out.println(featuredarticle);
        return R.ok(featuredarticleService.updateByPrimaryKey(featuredarticle));
    }

    //删除
    @DeleteMapping
    public R deleteByPrimaryKey(int articleId) {
        return R.ok(featuredarticleService.deleteByPrimaryKey(articleId));
    }

    //模糊查询
//    @GetMapping("/findbytitle")
//    public R findByTitle(String title){
//        return R.ok(featuredarticleService.findByTitle(title));
//    }

    //根据咨询师id查询文章
    @GetMapping("/findbyconsultantid")
    public R findByConsultantId(int consultantId){
        return R.ok(featuredarticleService.findByConsultantId(consultantId));
    }

    //   课程收藏表 和 咨询师表 查询
    @GetMapping("/findcoursefavoriteandconsultant")
    public R findCourseFavoriteAndConsultant(){
        return R.ok(featuredarticleService.findCourseFavoriteAndConsultant());
    }

    //新增
    @PostMapping
    public R insert(@RequestBody Featuredarticle featuredarticle){
        System.out.println(featuredarticle);
        return R.ok(featuredarticleService.insert(featuredarticle));
    }

    //
    //富文本编辑器上传
//    @PostMapping("/insertfeaturedarticle")
//    public R insertFeaturedarticle(Featuredarticle featuredarticle) {
//        System.out.println(featuredarticle);
//        return R.ok(featuredarticleService.insertFeaturedarticle(featuredarticle));
//    }

    @GetMapping("/findarticlebyid")
    public R findArticlebyId(int articleId) {
        Featuredarticle featuredarticle=featuredarticleService.findArticlebyId(articleId);
        return R.ok(featuredarticle);
    }
}
